<?php
define('IN_ECS', true);
date_default_timezone_set('prc');

require(dirname(__FILE__) . '/includes/init.php');

//require_once('./includes/upload.php'); //多张图片
require_once('./includes/picture.php');
// 发布活动记录
if ($_REQUEST['act'] == 'act_publish') {
    $activity_name = isset($_REQUEST['activity_name'])?trim($_REQUEST['activity_name']):'';
    $shop_name = isset($_REQUEST['shop_name'])?trim($_REQUEST['shop_name']):'';
    //$activity_cover = picture::uploaddir($_FILES['activity_cover']['name'],$_FILES['activity_cover']['tmp_name']);
    $activity_cover = isset($_REQUEST['activity_cover'])?trim($_REQUEST['activity_cover']):'';
    $user_id = isset($_REQUEST['user_id'])?trim($_REQUEST['user_id']):'';
    $activity_date = isset($_REQUEST['activity_date'])?trim($_REQUEST['activity_date']):'';
    $activity_describe = isset($_REQUEST['activity_describe'])?trim($_REQUEST['activity_describe']):'';
    $activity_address = isset($_REQUEST['activity_address'])?trim($_REQUEST['activity_address']):'';
    $activity_re_time = date("Y-m-d H:i:s");
    $friend_id = isset($_REQUEST['friend_id'])?trim($_REQUEST['friend_id']):'';
    $private = isset($_REQUEST['private'])?trim($_REQUEST['private']):1;
   
    if(empty($activity_name)){
        Response::json(441,"活动主题不能为空",$activity_name);
    }elseif (strlen($activity_name>60)){
        Response::json(442,"活动名过长",$activity_name);
    }
    if(empty($activity_cover)){
        Response::json(443,"活动封面不能为空",$activity_cover);
    }
    if(empty($user_id)) {
        Response::json(445,"发布者豆瓣号不能为空",$user_id);
    }else if (!is_numeric($user_id) || strlen($user_id) != 8) {
            Response::json(444, "用户豆瓣号不合法", $user_id);
        }
    if(empty($activity_date)){
        Response::json(445,"活动日期不能为空",$activity_date);
    }
    if(empty($activity_describe)) {
        Response::json(446, "活动描述不能为空", $activity_describe);
    }


    $sql = "INSERT INTO ". $ecs->table('activity') . " (activity_name, activity_cover,activity_date,user_id,activity_describe,activity_address,status,activity_re_time,friend_id,shop_name,private)". VALUES."('$activity_name','$activity_cover','$activity_date','$user_id','$activity_describe','$activity_address',1,'$activity_re_time','$friend_id','$shop_name','$private')" ;
    $res1=$db->query($sql);
    $rows = mysql_affected_rows();
    $sql = "SELECT * FROM ".$ecs->table('activity')." WHERE (activity_re_time = '$activity_re_time'and user_id = '$user_id')";
    $row = $db->getRow($sql);
    $activity_id = $row['activity_id'];
    $sql = "INSERT INTO " . $ecs->table('user_activity') . " (user_id,activity_id,status)" . VALUES . "($user_id,'$activity_id',1)";
    $res=$db->query($sql);
    $rows2 = mysql_affected_rows();
    if ($rows2 > 0) {
         $friend_id=explode(',',$friend_id);
    } else {
        Response::json(435, "数据上传失败");
    }
        if($rows > 0) {
            //如果有参与者将参与者添加到用户活动表
            if (!empty($friend_id)) {
               foreach ($friend_id as $value) {
                    $sql = "INSERT INTO " . $ecs->table('user_activity') . " (user_id,activity_id,status)" . VALUES . "('$value','$activity_id',1)";
                    $db->query($sql);
                    $rows1 = mysql_affected_rows();
                } 
            }

            if ($res1) {
                Response::json(210, "数据上传成功", $row);
            } else {
                Response::json(435, "数据上传失败", $row);
            }

    }
}


//发布影集
if ($_REQUEST['act'] == 'publish_pa') {
    $pa_describe = isset($_REQUEST['pa_describe']) ? trim($_REQUEST['pa_describe']) : '';
    $user_id = isset($_REQUEST['user_id']) ? trim($_REQUEST['user_id']) : '';
    $activity_id = isset($_REQUEST['activity_id']) ? trim($_REQUEST['activity_id']) : '';
    $picture_address = isset($_REQUEST['pic']) ? trim($_REQUEST['pic']) : '';
    $picture_address =explode(',',$picture_address);
    $pa_datetime = date("y-m-d h:i:s", time());
    //图片处理
    //$count = count($_FILES['pic']['name']);

    /*if ($count>1) {
       for ($i = 0; $i < $count; $i++) {
            if (!empty($_FILES['pic']['name'][$i])) {
                $files_name[] = $_FILES['pic']['name'][$i];
                $files_tmp[] = $_FILES['pic']['tmp_name'][$i];
            }
        }
        //删除相同的元素
    $file_name = formatArray($files_name);
    $file_tmp = formatArray($files_tmp);

    }else{
         $file_name = $_FILES['pic']['name'];
        $file_tmp = $_FILES['pic']['tmp_name'];
    }*/

    if (!empty($user_id)) {
        $sql = "SELECT user_name FROM " . $ecs->table(user) . " WHERE user_id = '$user_id'";
        $user_name = $db->getOne($sql);
        if (empty($user_id)) {
            return Response::json(448, "用户id不存在");
        }
    } else {
        return Response::json(449, "用户id不能为空");
    }
    if (empty($activity_id)) {
        return Response::json(450, "活动id不能为空");
    } else {
        $sql = "SELECT activity_name FROM " . $ecs->table(activity) . " WHERE activity_id = '$activity_id'";
        $activity_name = $db->getOne($sql);   //获取活动名称
        if (empty($activity_name)) {
            return Response::json(448, "活动id不存在");
        }
    }
    if ($count > 9) {
        return Response::json(447, "图片数量超过9张");
    } /*else {
        $picture_address = picture::uploaddir($file_name, $file_tmp);
    }*/

    $sql = "SELECT pa_id FROM " . $ecs->table('picture_album') . " WHERE (user_id = '$user_id' and activity_id='$activity_id')";
    $is_pa = $db->getOne($sql);
    if (empty($is_pa)) {
        $sql = "INSERT INTO " . $ecs->table('picture_album') . " (pa_describe,user_id,activity_id,pa_datetime,status)" . VALUES . "('$pa_describe','$user_id','$activity_id','$pa_datetime',1)";
        $db->query($sql);                  //将影集描述,用户id,活动id,影集创建时间,影集状态 插入数据库
        $row = mysql_affected_rows(); 
    }

   
    if ($row > 0) {
        $sql = "SELECT pa_id FROM " . $ecs->table('picture_album') . " WHERE (user_id = '$user_id' and pa_datetime='$pa_datetime')";
        $pa_id = $db->getOne($sql);
        if (empty($pa_id)) {

            return Response::json(437, '数据上传失败');
        }
        if( is_array($picture_address) ){
            foreach ($picture_address as $value) {
                $sql = "INSERT INTO " . $ecs->table('picture') . " (picture_address,pa_id,status)" . VALUES . "('$value','$pa_id',1)";//将图片插入数据库
                $db->query($sql);
                $rows = mysql_affected_rows();
                $sql1 = "SELECT picture_id FROM " . $ecs->table('picture') . " WHERE picture_address='$value'";//获取图片id
                $picture_id[] = $db->getOne($sql1);
            }
        }else{
           $sql = "INSERT INTO " . $ecs->table('picture') . " (picture_address,pa_id,status)" . VALUES . "('$picture_address','$pa_id',1)";//将图片插入数据库
                $db->query($sql);
                $rows = mysql_affected_rows();
                $id=$db->query('select last_insert_id()');
                $sql = "SELECT LAST_INSERT_ID()";
                $picture_id = $db->getOne($sql);
                /*$sql1 = "SELECT picture_id FROM " . $ecs->table('picture') . " WHERE picture_id='$picture_id'";//获取图片id
                $picture_id = $db->getOne($sql1);*/
        }

        
        if ($rows > 0) {
            $arr = array(
                '$pa_id' => $pa_id,
                '$picture_id' => $picture_id
            );

            return Response::json(211, "数据存入数据库", $arr);
        } else {
            return Response::json(438, "数据上传失败");
        }
    }
}



//删除影集
    if ($_REQUEST['act'] =='delpa') {
        $pa_id = isset($_REQUEST['pa_id']) ? trim($_REQUEST['pa_id']) : '';
        if (empty($pa_id)) {
            Response::json(490, "获取影集id失败");
        } elseif (isset_paid($pa_id)) {
            Response::json(494, "该影集不存在");
        }
        $sql1 = "UPDATE " . $ecs->table('picture_album') . " SET status=0 WHERE pa_id = '$pa_id'";
        $db->query($sql1);
        $row = mysql_affected_rows();
        if ($row > 0) {
            if (!isset_pic($pa_id)) {
                $sql = "UPDATE " . $ecs->table('picture') . " SET status='1' WHERE pa_id='$pa_id'";
                $db->query($sql);
                $rows = mysql_affected_rows();
                if ($rows > 0) {
                    Response::json(219, "删除成功");
                } else {
                    Response::json(493, "数据删除失败");
                }

            }
        } else {
            Response::json(494, "删除影集失败");
        }
    }
//修改影集(获取影集列表)
    if ($_REQUEST['act'] =='updpalist') {
        $pa_id = isset($_REQUEST['pa_id']) ? trim($_REQUEST['pa_id']) : '';
        $sql = "SELECT pa_describe FROM " . $ecs->table('picture_album') . " WHERE (pa_id='$pa_id' and status=1)";
        $pa_describe = $db->getOne($sql);
        if (!empty($pa_describe)) {
//       echo json_encode($pa_describe);
            $sql1 = "SELECT * FROM " . $ecs->table('picture') . " WHERE (pa_id='$pa_id' and status=1)";
            $picture = $db->getAll($sql1);
            if (!empty($picture)) {
//            echo json_encode($picture);
                $arr = array(
                    'pa_describe' => $pa_describe,
                    'picture' => $picture
                );
                Response::json(201, "获取成功", $arr);
            } else {
                Response::json(494, "读取失败");
            }
        }

    }

//修改操作
    if ($_REQUEST['act'] =='update') {
        $pa_describe = isset($_REQUEST['pa_describe']) ? trim($_REQUEST['pa_describe']) : '';
        $picture_id = isset_pic($_REQUEST['picture_id']) ? trim($_REQUEST['picture_id']) : '';
        $pa_id = isset($_REQUEST['pa_id']) ? trim($_REQUEST['pa_id']) : '';
        $pic_num = count($picture_id);
        if (mb_strlen($pa_describe) > 150) {
            Response::json(495, "影集描述最多为150字", $pa_describe);
        }
        $count = count($_FILES['pic']['name']);
        //删除为空的元素
        for ($i = 0; $i < $count; $i++) {
            if (!empty($_FILES['pic']['name'][$i])) {
                $files_name[] = $_FILES['pic']['name'][$i];
                $files_tmp[] = $_FILES['pic']['tmp_name'][$i];
            }
        }
        //删除相同的元素
        $file_name = formatArray($files_name);
        $file_tmp = formatArray($files_tmp);

        if ($count > 9) {
            return Response::json(447, "图片数量超过9张");
        } else {
            $picture_address = picture::uploaddir($file_name, $file_tmp);
        }
        $sql = "UPDATE " . $ecs->table('picture_album') . " SET pa_describe='$pa_describe' WHERE pa_id = '$pa_id'";
        $db->query($sql);
        $row = mysql_affected_rows();
        if ($row > 0) {
            echo json_encode($pa_describe);
        } else {
            Response::json(448, "修改失败");
        }
        for ($i = 0; $i < $pic_num; $i++) {
            $sql1 = "UPDATE " . $ecs->table('picture') . " SET pic_address='$picture_address[$i]' WHERE picture_id = '$picture_id'";
            $db->query($sql1);
            $rows = mysql_affected_rows();
            if ($rows > 0) {
                for ($j = $pic_num; $j < $count; $j++) {
                    $sql = "INSERT INTO " . $ecs->table('picture') . " (picture_address,pa_id,status)" . VALUES . "('$picture_address[$j]','$pa_id',1)";
                    $db->query($sql);
                    $rows1 = mysql_affected_rows();
                    $sql1 = "SELECT picture_id FROM " . $ecs->table('picture') . " WHERE picture_address='$value'";
                    $picture_id[] = $db->getOne($sql1);
                }
                if ($rows1 > 0) {
                    $arr = array(
                        'pa_describe' => $pa_describe,
                        'pic_id' => $picture_id
                    );


                    return Response::json(211, "数据修改成功", $picture_id);
                } else {
                    return Response::json(438, "数据上传失败");
                }

            } else {
                Response::json(449, "修改失败");
            }
        }


    }


//时间轴
    if (($_REQUEST['act'] == 'timer_shaft')) {
        $_POST['user_id'] = isset($_POST['user_id']) ? trim($_POST['user_id']) : '';
        $page = isset($_POST['Page']) ? trim($_POST['Page']) : '';
        
        $page_start = ($page - 1) * $page_size;


        $page_start=$_POST['start'];
        $page_size = $_POST['size'];//每页条数
        // if (empty($page)) {
        //     Response::json(471, "获取当前页失败");
        // }
        if (!empty($_POST['user_id'])) {
            $sql = "SELECT user_name,user_sex,user_pic,user_id" .
                " FROM " . $ecs->table('user') .
                " WHERE  user_id = '" . $_POST['user_id'] . "' ";
            $row1 = $db->getRow($sql);//查询基本信息顶端的用户名，头像，性别

            //查询是否大v
            $sql = "SELECT id" .
                " FROM " . $ecs->table('dv') .
                " WHERE  user_id = '" . $_POST['user_id'] . "' AND status=1 ";
            $dv = $db->getRow($sql);
            if ($dv) {
                $row1['is_dv']=1;
            }else{
                $row1['is_dv']=1;
            }

            /*$sql = "SELECT activity_id,activity_date,share_time" .
                " FROM " . $ecs->table('share_activity') .
                " WHERE  user_id = '" . $_POST['user_id'] . "' AND status=1 " .
                "ORDER BY activity_date,share_time" . " LIMIT $page_start,$page_size ";*/
           $sql = "SELECT activity_id,user_id,status" .
                " FROM " . $ecs->table('user_activity') .
                " WHERE  user_id = '" . $_POST['user_id'] . "' AND status=1 " .
                " LIMIT $page_start,$page_size ";
            $row6 = $db->getAll($sql);//查询活动id,发布时间,活动时间

            foreach ($row6 as $key => $value) {
                $sql = "SELECT activity_id,activity_name,activity_cover,activity_re_time,activity_date,activity_address,fab_num,activity_describe,private" . " FROM " . $ecs->table('activity') .
                    " WHERE  activity_id = '" . $value['activity_id'] . "' ";//查询活动名称，封面，发布时间，地址，点赞数，活动描述
                $row2 = $db->getRow($sql);
                $sql = "SELECT user_name,user_sex,user_pic" .
                    " FROM " . $ecs->table('user') .
                    " WHERE  user_id = '" . $row2['user_id'] . "' ";
                $row5 = $db->getRow($sql);       //查询发布者信息 ;

                $sql = "SELECT ecs_user.user_name,ecs_user.user_pic,ecs_user.user_id FROM " . $ecs->table('user_activity') . "LEFT JOIN " . $ecs->table('user') . "ON ecs_user.user_id = ecs_user_activity.user_id" . " WHERE ecs_user_activity.activity_id ='" . $value['activity_id'] . "'";
                $row3 = $db->getAll($sql);//查询活动参与者用户名，头像，ID

//        $sql = "select count(*) from".$ecs->table('like')."LEFT JOIN ".$ecs->table('user')."ON ecs_like.user_id=ecs_user.user_id"." WHERE ecs_like.activity_id ='" .$_POST['activity_id']."'";
                $row4 = count($row3);//计算参与者数量

                $now_time = strtotime(date("Y-m-d H:i:s"));//当前时间
                $re_time = strtotime($row6['share_time']);//活动发布时间
                $time = $now_time - $re_time;//计算时间差

                $row[] = array(
                    'top_information' => $row1,
                    'publisher' => $row5,
                    'middle_information' => $row2,
                    'count_visit' => $row4,
                    'time_difference' => $time,
                    'member' => $row3
                );
            }


            return Response::json(200, "查询数据成功", $row);
        } else {
            return Response::json(450, "参与者与活动不匹配", $id);


        }

    }
//好友状态
    if (($_REQUEST['act'] == 'friend_space')) {
        $_POST['user_id'] = isset($_POST['user_id']) ? trim($_POST['user_id']) : '';//获取用户id
        //$page = isset($_POST['Page']) ? trim($_POST['Page']) : '';
        $page_start = $_POST['start'];
        $page_size = $_POST['size'];
       
        /*if (empty($page)) {
            Response::json(471, "获取当前页失败");
        }*/
        if (!empty($_POST['user_id'])) {

            
            $sql1 = "SELECT friend_id FROM " . $ecs->table('friend') . " WHERE user_id='" . $_POST['user_id'] . "' ";
            $sql = "SELECT activity_id,activity_date,share_time" .
                " FROM " . $ecs->table('share_activity') .
                " WHERE  user_id in ($sql1) OR user_id = '" . $_POST['user_id'] . "' AND status=1 " .
                "ORDER BY activity_date,share_time" . " LIMIT $page_start,$page_size";
            $row1 = $db->getAll($sql);//查询活动id,发布时间,活动时间
            foreach ($row6 as $key => $value) {
                $sql = "SELECT activity_id activity_name,activity_cover,activity_re_time,activity_date,activity_address,fab_num,activity_describe,privite" .
                    " FROM " . $ecs->table('activity') .
                    " WHERE  activity_id = '" . $value['activity_id'] . "' ";//查询活动名称，封面，发布时间，地址，点赞数，活动描述
                $row2 = $db->getRow($sql);
                $sql = "SELECT user_name,user_sex,user_pic" .
                    " FROM " . $ecs->table('user') .
                    " WHERE  user_id = '" . $row2['user_id'] . "' ";
                $row5 = $db->getRow($sql);       //查询发布者信息 ;

                $sql = "SELECT ecs_user.user_name,ecs_user.user_pic,ecs_user.user_id FROM " . $ecs->table('user_activity') . "LEFT JOIN " . $ecs->table('user') . "ON ecs_user.user_id = ecs_user_activity.user_id" . " WHERE ecs_user_activity.activity_id ='" . $value['activity_id'] . "'";
                $row3 = $db->getAll($sql);//查询活动参与者用户名，头像，ID

//        $sql = "select count(*) from".$ecs->table('like')."LEFT JOIN ".$ecs->table('user')."ON ecs_like.user_id=ecs_user.user_id"." WHERE ecs_like.activity_id ='" .$_POST['activity_id']."'";
                $row4 = count($row3);//计算参与者数量
                $now_time = strtotime(date("Y-m-d H:i:s"));//当前时间
                $re_time = strtotime($row6['share_time']);//活动发布时间
                $time = $now_time - $re_time;//计算时间差

                $row[] = array(
                    'top_information' => $row1,
                    'publisher' => $row5,
                    'middle_information' => $row2,
                    'count_visit' => $row4,
                    'time_difference' => $time,
                    'member' => $row3
                );
            }

            return Response::json(200, "查询数据成功", $row);
        } else {
            return Response::json(450, "参与者与活动不匹配", $id);


        }
    } //大v状态
    elseif ($_REQUEST['act'] == 'dv') {
        $_POST['user_id'] = isset($_POST['user_id']) ? trim($_POST['user_id']) : '';//获取用户id
        /*$page = isset($_POST['Page']) ? trim($_POST['Page']) : '';
        $page_size = 10;//每页条数
        $page_start = ($page - 1) * $page_size;
        if (empty($page)) {
            Response::json(471, "获取当前页失败");
        }*/
        $page_start = $_POST['start'];
        $page_size = $_POST['size'];
        if (!empty($_POST['user_id'])) {
            $sql1 = "SELECT user_id FROM " . $ecs->table('dv');
            $sql = "SELECT activity_id,activity_date,share_time" .
                " FROM " . $ecs->table('share_activity') .
                " WHERE  user_id in ($sql1)  AND status=1 " .
                "ORDER BY activity_date,share_time" . " LIMIT $page_start,$page_size";
            $row6 = $db->getAll($sql);//查询活动id,发布时间,活动时间


            $row6 = $db->getAll($sql);//查询活动id,发布时间,活动时间
            foreach ($row6 as $key => $value) {
                $sql = "SELECT activity_name,activity_cover,activity_re_time,activity_date,activity_address,fab_num,activity_describe" .
                    " FROM " . $ecs->table('activity') .
                    " WHERE  activity_id = '" . $value['activity_id'] . "' ";//查询活动名称，封面，发布时间，地址，点赞数，活动描述
                $row2 = $db->getRow($sql);
                $sql = "SELECT user_name,user_sex,user_pic" .
                    " FROM " . $ecs->table('user') .
                    " WHERE  user_id = '" . $row2['user_id'] . "' ";
                $row5 = $db->getRow($sql);       //查询发布者信息 ;

                $sql = "SELECT ecs_user.user_name,ecs_user.user_pic,ecs_user.user_id FROM " . $ecs->table('user_activity') . "LEFT JOIN " . $ecs->table('user') . "ON ecs_user.user_id = ecs_user_activity.user_id" . " WHERE ecs_user_activity.activity_id ='" . $value['activity_id'] . "'";
                $row3 = $db->getAll($sql);//查询活动参与者用户名，头像，ID

//        $sql = "select count(*) from".$ecs->table('like')."LEFT JOIN ".$ecs->table('user')."ON ecs_like.user_id=ecs_user.user_id"." WHERE ecs_like.activity_id ='" .$_POST['activity_id']."'";
                $row4 = count($row3);//计算参与者数量

                $now_time = strtotime(date("Y-m-d H:i:s"));//当前时间
                $re_time = strtotime($row6['share_time']);//活动发布时间
                $time = $now_time - $re_time;//计算时间差

                $row[] = array(
                    'top_information' => $row1,
                    'publisher' => $row5,
                    'middle_information' => $row2,
                    'count_visit' => $row4,
                    'time_difference' => $time,
                    'member' => $row3
                );
            }

            return Response::json(200, "查询数据成功", $row);
        } else {
            return Response::json(450, "参与者与活动不匹配", $id);


        }
    }
    if ($_REQUEST['act'] == 'add_acfriend') {

        $user_id = isset($_REQUEST['user_id']) ? trim($_REQUEST['user_id']) : '';
        $sql = "SELECT * FROM " . $ecs->table('friend') . "LEFT JOIN " . $ecs->table('user') . "ON ecs_user.user_id=ecs_friend.friend_id" . " WHERE (ecs_friend.user_id ='$user_id and ecs_friend.status=1)'";
        $row = $db->getAll($sql);
        if (!empty($row)){
            Response::json(204, "获取好友信息成功", $row);
        }
        else {
            Response::json(433, "好友信息读取失败");
        }
    }



if ($_REQUEST['act'] == 'pa_list') {
        $user_id = isset($_REQUEST['user_id']) ? trim($_REQUEST['user_id']) : '';
        $activity_id = isset($_REQUEST['activity_id']) ? trim($_REQUEST['activity_id']) : '';
        $sql = "SELECT activity_name FROM " . $ecs->table('activity') . " WHERE activity_id='$activity_id'";//获取活动名称
        $activity_name = $db->getOne($sql);
        //$sql1 = "SELECT * FROM " . $ecs->table('picture_album') . " WHERE (activity_id = '$activity_id' and status=1) ORDER BY pa_datetime";//获取影集信息
        $sql1 = "SELECT * FROM " . $ecs->table('picture_album') . " WHERE (activity_id = '$activity_id' and user_id = '$user_id' and status=1) ORDER BY pa_datetime";//获取影集信息
        $rows = $db->getAll($sql1); 
        if (!empty($rows)) {
            foreach ($rows as $key => $value) {
                if ($value['user_id'] == $user_id) {
                    $is_publish = true;
                } else {
                    $is_publish = false;
                }
                //echo json_encode($is_publish);//是否为影集发布者
                //echo json_encode($rows[$key]);
                $pa_id=$value['pa_id'];
                $sql2 = "SELECT * FROM " . $ecs->table('picture') . "WHERE (pa_id='$pa_id' and status=1)";
                $row = $db->getAll($sql2);
                if (!empty($row)) {
                    //echo json_encode($row);
                    $arr = array(
                        'is_publish' => $is_publish,
                        'pa_list' => $value[$key],
                        'pic_info' => $row
                    );
                    Response::json(201, "数据返回成功", $arr);
                }

            }
        } else {

            Response::json(491, "数据读取失败");
        }
    }

// 删除数组中相同元素，只保留一个相同元素
    function formatArray($array)
    {
        sort($array);
        $tem = "";
        $temarray = array();
        $j = 0;
        for ($i = 0; $i < count($array); $i++) {
            if ($array[$i] != $tem) {
                $temarray[$j] = $array[$i];
                $j++;
            }

            $tem = $array[$i];
        }
        return $temarray;
    }

//判断是否是影集发布者
    function is_pauser($user_id, $pa_id)
    {
        $sql = "SELECT $user_id FROM " . $GLOBALS['ecs']->table('picture_album') . " WHERE (pa_id = '$pa_id' and status=1)";
        $pauser_id = $GLOBALS['db']->getOne($sql);
        return $user_id = $pauser_id ? true : false;
    }

    function isset_paid($pa_id)
    {
        $sql = "SELECT  pa_describe FROM " . $GLOBALS['ecs']->table('picture_album') . " WHERE (pa_id = '$pa_id' and status=1)";
        $pa_describe = $GLOBALS['db']->getOne($sql);
        return empty($pa_describe);
    }

    function isset_pic($pa_id)
    {
        $sql = "SELECT  picture_id FROM " . $GLOBALS['ecs']->table('picture') . " WHERE (pa_id = '$pa_id' and status=1)";
        $picture_id = $GLOBALS['db']->getOne($sql);
        return empty($picture_id);
    }
